﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 01.04.2008
 * Zeit: 12:54
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using Gamadus.Engine;

namespace Gamadus.Builder.Ast
{
	/// <summary>
	/// Description of Constant.
	/// </summary>
	public class Constant : Expression
	{
		readonly string m_value;
		
		public Constant(Irony.Compiler.AstNode node, SourceLocation location) : base(node, location)
		{
			switch(node.Term.Name)
			{
				case "number":
					m_value = (node as Irony.Compiler.Token).Value.ToString();
					break;
				case "String":
					m_value = '"'+(string)(node as Irony.Compiler.Token).Value+'"';
					break;
				default:
					throw new ArgumentException("Invalid constant");
			}
		}
		
		public override string ToString()
		{
			return m_value;
		}
		
		public override string Generate()
		{
			return m_value;
		}
		
//		protected internal override Microsoft.Scripting.Ast.Expression Generate()
//		{
//			if(m_value.GetType() == typeof(double))
//				return MSAst.Ast.New(typeof(GmlVar).GetConstructor(
//					new Type[]{typeof(real)}),
//					MSAst.Ast.New(typeof(real).GetConstructor(new Type[]{typeof(double)}),MSAst.Ast.Constant((double)m_value)));
//			else if(m_value.GetType() == typeof(int))
//				return MSAst.Ast.New(typeof(GmlVar).GetConstructor(
//					new Type[]{typeof(real)}),
//					MSAst.Ast.New(typeof(real).GetConstructor(new Type[]{typeof(double)}),MSAst.Ast.Constant((double)(int)m_value)));
//			else if(m_value.GetType() == typeof(string))
//				return MSAst.Ast.New(typeof(GmlVar).GetConstructor(
//					new Type[]{typeof(string)}),
//					MSAst.Ast.Constant((string)m_value));
//			
//			throw new InvalidCastException();
//		}
	}
}
